import http from "@/lib/http";
import {route} from "ziggy-js";

// 新增 RESTful 路由生成器
const restfulRoutes = (base) => ({
    create: `${base}.store`,
    update: `${base}.update`,
    show: `${base}.show`,
    delete: `${base}.destroy`,
    index: `${base}.index`
});

export default function useRequest(basePath) {
    const routes = restfulRoutes(basePath);

    return {
        createApi: (form) => http.post(route(routes.create), form),
        updateApi: (id, form) => http.put(route(routes.update, { id }), form),
        showApi: (id) => http.get(route(routes.show, { id })),
        deleteApi: (id) => http.delete(route(routes.delete, { id })),
        indexApi: (params) => http.get(route(routes.index), { params })
    }
}
